package com.hjn.springcloud.controlloer;

import com.hjn.springcloud.entities.CommonResult;
import com.hjn.springcloud.entities.Payment;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
@Slf4j
@RequestMapping("/consumer/order")
public class ConsumerOrderController {
    //支付url
//    public static final String PAYMENT_URL = "http://127.0.0.1:8001/payment/";
    public static final String PAYMENT_URL = "http://COULD-PROVIDER-PAYMENT/payment/";

    //添加
    public static final String CREATCTL_NAME = "create/";
    public static final String GETCTL_NAME = "get/";

    @Autowired
    private RestTemplate restTemplate;

    //添加订单
    @GetMapping("/creat")
    public CommonResult<Payment> creat(Payment payment) {
        log.info("调用订单");
        return restTemplate.postForObject(PAYMENT_URL + CREATCTL_NAME, payment, CommonResult.class);
    }

    //    查询订单
    @GetMapping("/get/{id}")
    public CommonResult gerPayment(@PathVariable("id") Long id) {
        return restTemplate.getForObject(PAYMENT_URL + GETCTL_NAME + id, CommonResult.class);
    }

    @GetMapping("/test")
    public String test(){
        return "success";
    }
}
